package no.ntnu.fp.su;

import java.sql.Timestamp;

/**
 * Message that can be sent between master and local watch
 * 
 * @author abs
 * 
 */
public class Message {

	String text;
	Platform from;
	Timestamp timestamp;

	/**
	 * 
	 * @return {@link Timestamp} time of message
	 */
	public Timestamp getTimestamp() {
		return timestamp;
	}

	/**
	 * 
	 * @param {@link Timestamp} time of message
	 */
	public void setTimestamp(Timestamp timestamp) {
		this.timestamp = timestamp;
	}

	/**
	 * 
	 * @return {@link String} content of message
	 */
	public String getText() {
		return text;
	}

	/**
	 * 
	 * @param {@link String} content of message
	 */
	public void setText(String text) {
		this.text = text;
	}

	/**
	 * 
	 * @return {@link Platform} sender, returns {@link null} if sender was
	 *         MASTER
	 */
	public Platform getFrom() {
		return from;
	}

	/**
	 * @param {@link Platform} sender, {@link null} if sender was MASTER
	 */
	public void setFrom(Platform from) {
		this.from = from;
	}

	/**
	 * parse and prepare message to be sent, with headers
	 */
	public String toString() {
		// -> "message" - "from" - "timestamp(milliseconds)" - "<the message>"
		return "message" + Watch.SEPARATOR + getFrom().toString()
				+ Watch.SEPARATOR + +getTimestamp().getTime() + Watch.SEPARATOR
				+ getText().replace(Watch.SEPARATOR.charAt(0), '|');
	}

}
